package com.hzp.micromall.content.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzp.micromall.common.core.api.CommonPage;
import com.hzp.micromall.content.dao.PrefrenceAreaDao;
import com.hzp.micromall.content.entity.PrefrenceArea;
import com.hzp.micromall.content.service.PrefrenceAreaService;
import com.hzp.micromall.content.vo.QueryParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 优选专区 服务实现类
 * </p>
 *
 * @author houzipeng
 * @since 2022-03-08 10:15:14
 */
@Service
public class PrefrenceAreaServiceImpl extends ServiceImpl<PrefrenceAreaDao, PrefrenceArea> implements PrefrenceAreaService {

    @Autowired
    private PrefrenceAreaDao prefrenceAreaDao;

    @Override
    public int create(PrefrenceArea area) {
        return prefrenceAreaDao.insert(area);
    }

    @Override
    public List<PrefrenceArea> listAll() {
        return prefrenceAreaDao.selectList(null);
    }

//    @Override
//    public CommonPage<PrefrenceArea> getPage(QueryParams params) {
//        Page<PrefrenceArea> page = new Page<>(params.getPageNum(), params.getPageSize());
//        prefrenceAreaDao.getPage(page, params);
//        return new CommonPage<>(page.getCurrent(), page.getTotal(), page.getSize(), page.getRecords());
//    }

    @Override
    public CommonPage<PrefrenceArea> getPage(String keyword, Integer showStatus, String startTime, String endTime, Integer pageNum, Integer pageSize) {
        Page<PrefrenceArea> page = new Page<>(pageNum, pageSize);
        prefrenceAreaDao.getPage(page, keyword, showStatus, startTime, endTime);
        return new CommonPage<>(page.getCurrent(), page.getTotal(), page.getSize(), page.getRecords());
    }

    @Override
    public int update(Long id, PrefrenceArea prefrenceArea) {
        prefrenceArea.setId(id);
        return prefrenceAreaDao.updateById(prefrenceArea);
    }

    @Override
    public int updateShowStatus(List<Long> ids, Integer newShowStatus) {
        PrefrenceArea prefrenceArea = new PrefrenceArea();
        prefrenceArea.setShowStatus(newShowStatus);
        LambdaQueryWrapper<PrefrenceArea> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(PrefrenceArea::getId, ids);
        return prefrenceAreaDao.update(prefrenceArea, wrapper);
    }

    @Override
    public int delete(List<Long> ids) {
        return prefrenceAreaDao.deleteBatchIds(ids);
    }
}
